package com.csdj.t309springboot.controller;
import com.csdj.t309springboot.entity.User;
import com.csdj.t309springboot.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Controller
public class TestController {
    @Resource
    private UserService userService;
    private Logger log = LoggerFactory.getLogger("test");




    @GetMapping("demo")
    public String index(Model model){
        List<String> list = new ArrayList<>();
        list.add("tom");
        list.add("tony");
        list.add("cloud");
        list.add("three");

        User user = new User();
        user.setId(30);
        user.setName("张三");
        model.addAttribute("user",user);
        model.addAttribute("list",list);
        model.addAttribute("name","cloud");
        return "demo";
    }
    @ResponseBody
    @GetMapping("test")
    public String test(){
        return "SpringBoot Test";
    }

    @ResponseBody
    @GetMapping("/list")
    public List<User> hello(){
        List<User> list=userService.getAllUsers();

        return list;
    }



}
